package cn.itcast.manus.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker // 启用websocket消息代理功能
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        // 启用简单的消息代理，用于向客户端发送消息数据

        config.enableSimpleBroker("/queue");
        // 设置应用目标的前缀

        config.setApplicationDestinationPrefixes("/app");
    }


    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // 注册一个STOMP的端点，允许任何客户端访问
        /*registry.addEndpoint("/bs-dialog-websocket")
                .setAllowedOriginPatterns("*");*/
        registry.addEndpoint("/bs-dialog-websocket").setAllowedOriginPatterns("*");
    }

}